#pragma once 
#include"protocol.hpp"
#include <iostream>
using namespace std;
// 规定只允许加减乘除操作：
class cal
{

public:
    response excute(request s)
    {
        int x = s.geta();
        int y = s.getb();
        char op = s.getoper();
        response res;
        switch (op)
        {
        case '+':
            res.setresult(s.geta() + s.getb());
            break;
        case '-':
            res.setresult(s.geta() - s.getb());
            break;
        case '*':
            res.setresult(s.geta() * s.getb());
            break;
        case '/':
        {
            if (s.getb() == 0)
            {
                res.setcode(1); // 1除零错误
            }
            else
            {
                res.setresult(s.geta() / s.getb());
            }
        }
        break;
        case '%':
        {
            if (s.getb() == 0)
            {
                res.setcode(2); // 2 mod 0 错误
            }
            else
            {
                res.setresult(s.geta() % s.getb());
            }
        }
        break;
        default:
            res.setcode(3); // 非法操作
            break;
        }

        return res;
    }
};
